<template>
  <div class="app-container">
    <!-- 搜索筛选操作栏 -->
    <div class="filter-container clearfix">
      <el-input
        v-model="listQuery.buyer_user"
        placeholder="请输入买家账号"
        style="width: 200px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-input
        v-model="listQuery.seller_shopping"
        placeholder="请输入卖家店铺"
        style="width: 200px; margin-left: 10px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-input
        v-model="listQuery.seller_user"
        placeholder="请输入卖家账号"
        style="width: 200px; margin-left: 10px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-select
        v-model="listQuery.type"
        placeholder="请选择拍品类型"
        clearable
        style="width: 150px; margin-left: 10px"
        class="filter-item"
      >
        <el-option label="首次上拍" :value="0" />
        <el-option label="续拍商品" :value="1" />
      </el-select>
      <el-input
        v-model="listQuery.no"
        placeholder="请输入拍品编号"
        style="width: 200px; margin-left: 10px"
        class="filter-item"
        @keyup.enter.native="handleFilter"
      />
      <el-button
        v-waves
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        style="margin-left: 10px"
        @click="handleFilter"
      >
        搜索
      </el-button>
      <el-button
        v-waves
        class="filter-item"
        icon="iconfont qt-caozuo-xunhuan1"
        @click="clearFilter"
      >
        清除条件
      </el-button>
    </div>

    <!-- 表格 -->
    <el-table
      :key="tableKey"
      ref="table"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column label="买家账号" prop="user.user" align="center" />
      <el-table-column label="姓名" prop="user.name" align="center" />
      <el-table-column label="拍品编号" prop="product_id" align="center" />
      <el-table-column label="拍品名称" header-align="center" width="150">
        <template slot-scope="{ row }">
          <el-image
            v-if="row.product"
            style="width: 40px; height: 40px; text-align: center"
            :src="$store.state.settings.imgHost + row.product.image"
            :preview-src-list="[
              $store.state.settings.imgHost + row.product.image,
            ]"
          />
          <span
            v-if="row.product && row.product.name"
            style="vertical-align: top; margin-left: 10px"
          >{{ row.product.name }}</span>
        </template>
      </el-table-column>
      <el-table-column label="卖家店铺" align="center">
        <template slot-scope="{ row }">
          {{
            (row.seller_shopping && row.seller_shopping.name) ||
              (row.seller_shopping && row.seller_shopping.shopping_name)
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="卖家账号"
        prop="seller_user.user"
        align="center"
      />
      <el-table-column label="拍品类型" align="center">
        <template v-if="row.seller_shopping" slot-scope="{ row }">
          {{
            row.seller_shopping.type == 0
              ? "首次上拍"
              : row.seller_shopping.type == 1
                ? "续拍商品"
                : ""
          }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="实付" prop="real_pay" />
      <el-table-column
        align="center"
        label="平台服务费"
        prop="deal_server_money"
      />
      <el-table-column
        align="center"
        label="卖家结算金额"
        prop="seller_real_income"
      />
      <el-table-column
        align="center"
        label="成交时间"
        prop="created_at"
        width="170"
      />
    </el-table>

    <!-- 分页 -->
    <div v-if="total > 0" style="text-align: right">
      <pagination
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.per_page"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { getSuccessfulList } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'AuctionGoodSuccessful',
  components: {
    Pagination
  },
  directives: {
    waves
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        per_page: 20,
        buyer_user: undefined,
        seller_user: undefined,
        seller_shopping: undefined,
        no: undefined,
        type: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    clearFilter() {
      this.listQuery['buyer_user'] = undefined
      this.listQuery['seller_user'] = undefined
      this.listQuery['seller_shopping'] = undefined
      this.listQuery['no'] = undefined
      this.listQuery['type'] = undefined
      this.handleFilter()
    },
    getList() {
      this.listLoading = true
      getSuccessfulList(this.listQuery)
        .then((response) => {
          const { data, total } = response.data
          this.list = data
          this.total = total
        })
        .finally(() => {
          this.listLoading = false
        })
    }
  }
}
</script>
